package cn.hxzy.servlet;

import cn.hxzy.entity.Member;
import cn.hxzy.entity.News;
import cn.hxzy.entity.Work;
import cn.hxzy.entity.vo.PageObj;
import cn.hxzy.service.MemberService;
import cn.hxzy.service.NewsService;
import cn.hxzy.service.WorkService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/index")
public class IndexServlet extends HttpServlet {
    private NewsService newsService = new NewsService();
    private WorkService workService = new WorkService();
    private MemberService memberService = new MemberService();

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        try {
            List<News> all = newsService.findAll();
            req.setAttribute("news", all);
            List<Work> works = workService.findAll();
            req.setAttribute("works", works);
            List<Member> members = memberService.findAll();
            req.setAttribute("members", members);
            req.getRequestDispatcher("WEB-INF/jsp/index.jsp").forward(req, resp);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
